package com.ff.miaosha.controller;

import com.ff.miaosha.redis.RedisService;
import com.ff.miaosha.result.Result;
import com.ff.miaosha.service.MiaoshaUserService;
import com.ff.miaosha.vo.LoginVo;
import lombok.extern.slf4j.Slf4j;
import net.bytebuddy.asm.Advice;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;

@Controller
@RequestMapping("login")
@Slf4j
public class LoginController {

    @Autowired
    MiaoshaUserService miaoshaUserService;

    @Autowired
    RedisService redisService;

    @RequestMapping("to_login")
    public String toLogin(){
        return "login";
    }

    @ResponseBody
    @RequestMapping("do_login")
    public Result<Boolean> doLogin(HttpServletResponse response, @Valid LoginVo loginVo){
        log.info(loginVo.toString());
        //登录
        miaoshaUserService.login(response,loginVo);
        return Result.success(true);
    }
}
